package com.cloneoner.ui.shapes
{
	import flash.display.Graphics;
	import flash.display.Shape;


	/**
	 * @author Thibault Loup
	 */
	public class ShFilledTriangle extends Shape
	{
		
		
		// __________________________________________________________
		// -										 	  CONSTRUCTOR
		
		/**
		 * Constructor
		 * @param pColor The color of the object
		 * @param pWidth The width of the object in pixels.
		 * @param pHeight The height of the object in pixels.
		 */
		public function ShFilledTriangle( pColor:uint, pWidth:int=0, pHeight:int=0 )
		{
			_color = pColor;
			_width = pWidth;
			_height = (_width > 0 && pHeight == 0 ) ? _width : pHeight;
			
			_draw();
		}

		// __________________________________________________________
		// -										  PUBLICS METHODS
		
		/** The width of the object in pixels. */
		override public function set width(value : Number) : void
		{
			if ( _width == value) return;

			_width = value;
			_draw();
		}
		override public function get width() : Number
		{
			return _width;
		}
		
		/** The height of the object in pixels. */
		override public function set height(value : Number) : void
		{
			if ( _height == value) return;

			_height = value;
			_draw();
		}
		override public function get height() : Number
		{
			return _height;
		}
		
		/** The color of the object */
		public function set color(pValue : uint) : void
		{
			if ( _color == pValue) return;
			_color = pValue;
			_draw();
		}
		public function get color() : uint
		{
			return _color;
		}

		// __________________________________________________________
		// -										 PRIVATES METHODS

		/** @private */
		private function _draw() : void
		{
			var g : Graphics = this.graphics;

			const yy : int = int(_height / 2 + .5);

			g.clear();
			g.beginFill(_color);
			g.moveTo(0, -yy);
			g.lineTo(_width, 0);
			g.lineTo(0, yy);
			g.endFill();
		}


		/* VAR */
		private var _width : int;
		private var _height : int;
		private var _color : uint;
	}
}
